package cn.kgc.faqmanager.service.impl;

import cn.kgc.faqmanager.mapper.FaqsMapper;
import cn.kgc.faqmanager.pojo.Faqs;
import cn.kgc.faqmanager.pojo.FaqsExample;
import cn.kgc.faqmanager.service.FaqsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FaqsServiceImpl implements FaqsService {
    @Resource
    FaqsMapper faqsMapper;

    @Override
    public PageInfo<Faqs> select(Integer pageNum, Integer pageSize, Integer classId) {
        PageHelper.startPage(pageNum,pageSize);
        List<Faqs> faqsList;
        if(classId!=0){
            FaqsExample example=new FaqsExample();
            FaqsExample.Criteria criteria=example.createCriteria();
            criteria.andClassidEqualTo(classId);
            faqsList=faqsMapper.selectByExample01(example);
        }else{
            faqsList=faqsMapper.selectByExample01(null);
        }
        PageInfo<Faqs> pageInfo=new PageInfo<>(faqsList);
        return pageInfo;
    }

    @Override
    public Integer add(Faqs faqs) {
        int i=faqsMapper.insert(faqs);
        return i;
    }

    @Override
    public Faqs selectById(Integer id) {
        Faqs faqs=faqsMapper.selectByPrimaryKey(id);
        return faqs;
    }

    @Override
    public Integer update(Faqs faqs) {
        int i=faqsMapper.updateByPrimaryKey(faqs);
        return i;
    }

    @Override
    public Integer delete(Integer id) {
        int i=faqsMapper.deleteByPrimaryKey(id);
        return i;
    }
}
